package com.kyg.tjtoolmanager.module;

import com.kyg.tjtoolmanager.App;

/**
 * 标签读写器
 * 类型：工作台读写器=1，盘点读写器=2
 * 连接方式：串口=1，网口=2
 * 串口，波特率
 * 网口地址
 * 所属房间
 * 所属货架，层架，架位
 */
public class Reader {

    public String id;
    /**
     * 工作台读写器=1，盘点读写器=2
     */
    public int type = 1;
    /**
     * 串口=1，网口=2
     */
    public int conType = 1;
    public String serial = "";
    public int baud;
    public String ip = "";
    public int ipPort;

    public int houseId;
    public int jiaId;
    public int cengId;
    public int weiId;
    /**
     * -1 正在连接
     * 0 失败
     * 1 成功
     */
    public int conStatus = -1;

    public Reader() {
        this.id = System.currentTimeMillis() + "";
    }

    public String getReaderType() {
        if (type == 1) {
            return "工作台读写器";
        } else if (type == 2) {
            return "盘点读写器";
        }
        return "";
    }

    public String getConnectType() {
        if (conType == 1) {
            return "串口=" + serial + " 波特率=" + baud;
        } else if (conType == 2) {
            return "网口=" + ip + " 端口=" + ipPort;
        }
        return conType + "";
    }

    public String getAddress() {
        for (int i = 0; i < App.wareHouses.size(); i++) {
            if (houseId == App.wareHouses.get(i).houseId) {
                return App.wareHouses.get(i).name;
            }
        }
        return "";
    }

    @Override
    public String toString() {
        return "Reader{" +
                "id='" + id + '\'' +
                ", type=" + type +
                ", conType=" + conType +
                ", serial='" + serial + '\'' +
                ", baud=" + baud +
                ", ip='" + ip + '\'' +
                ", ipPort=" + ipPort +
                ", houseId=" + houseId +
                ", jiaId=" + jiaId +
                ", cengId=" + cengId +
                ", weiId=" + weiId +
                ", conStatus=" + conStatus +
                '}';
    }
}
